package ltd.zouzheng.myutils.spring.rest;

import org.springframework.util.MultiValueMap;

import java.util.Map;

/**
 * 封闭spring的RestTemplate工具
 *
 * @author zouzheng
 * @date 2021/4/13
 */
public class RestTemplateUtil {

    private static RestTemplateExt restTemplateExt;

    protected static void setRestTemplateExt(RestTemplateExt restTemplateExt) {
        RestTemplateUtil.restTemplateExt = restTemplateExt;
    }

    public static <T> T postForForm(String url, MultiValueMap<String, String> request, Class<T> responseType) {
        return restTemplateExt.postForForm(url, request, responseType);
    }

    public static <T> T postForForm(String url, MultiValueMap<String, String> request, Class<T> responseType, Map<String, ?> uriVariables) {
        return restTemplateExt.postForForm(url, request, responseType, uriVariables);
    }

    public static <T> T postForObject(String url, Object request, Class<T> responseType) {
        return restTemplateExt.postForObject(url, request, responseType);
    }

    public static <T> T postForObject(String url, Object request, Class<T> responseType, Map<String, ?> uriVariables) {
        return restTemplateExt.postForObject(url, request, responseType, uriVariables);
    }

    public static <T> T postForObject(String url, Object request, Class<T> responseType, Object... uriVariables) {
        return restTemplateExt.postForObject(url, request, responseType, uriVariables);
    }

    public static <T> T getForObject(String url, Class<T> responseType, Object... uriVariables){
        return restTemplateExt.getForObject(url, responseType, uriVariables);
    }

    public static <T> T getForObject(String url, Class<T> responseType, Map<String, ?> uriVariables){
        return restTemplateExt.getForObject(url, responseType, uriVariables);
    }

    public static <T> T getForObject(String url, Class<T> responseType){
        return restTemplateExt.getForObject(url, responseType);
    }
}
